﻿using System.Windows;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.CommandWpf;

namespace WPFWorkbookDesigner.ViewModel
{
    public abstract class WindowViewModelBase : ViewModelBase
    {
        private Window _interface;

        protected WindowViewModelBase()
        {
            CloseWindowCommand = new RelayCommand<Window>(Close);
        }

        /// <summary>
        /// 与ViewModel相关联的界面实例
        /// </summary>
        public Window Interface
        {
            protected get { return _interface; }
            set
            {
                _interface = value;
                RaisePropertyChanged();
            }
        }

        public virtual RelayCommand<Window> CloseWindowCommand { get; }
        protected virtual void Close(Window window)
        {
            window.Close();
        }

        protected virtual void SetInterfaceOwner(Window window)
        {
            Interface.Owner = window;
        }
    }
}